﻿<%@ Page Language="C#" AutoEventWireup="false" Inherits="Bee.Web.BeePageView" %>

<%@ Import Namespace="Bee.Web" %>
<%@ Import Namespace="Bee" %>
<%@ Import Namespace="System.Collections.Generic" %>
<form id='pageForm<%=PageId %>' action="<%=HtmlHelper.ForActionLink() %>" method="post">
<div class="formBar">
    <ul style="float: left; margin-right: 350px;">
        <li>
            <select id="conn">
                <option value="">请选择</option>
                <%
                    List<string> list = ViewData["ConnectionString"] as List<string>;
                    foreach (string item in list)
                    { %>
                <option value="<%=item %>">
                    <%=item %></option>
                <%} %>
            </select>
        </li>
    </ul>
</div>
</form>
<div id="treediv" style="float: left; display: block; margin: 10px; overflow: auto;
    width: 350px; border: solid 1px #CCC; line-height: 21px; background: #FFF;" layouth="56">
    <ul id="tree1" class="tree treeFolder expand">
    </ul>
</div>
<div region="center" id="divFileBody" title="文件源代码" style="display: none;">
</div>
<div style="float: left; display: block; margin: 10px; width: 600px;" layouth="56">
    <div id="flash-loader">
    </div>
    <div>
        <select id="databaseType">
            <option value="">请选择</option>
            <option value="sqlserver">sqlserver</option>
            <option value="oracle">oracle</option>
            <option value="sqlite">sqlite</option>
            <option value="mysql">mysql</option>
        </select>
    </div>
    <div id="sql-loader">
    </div>
</div>

<script type="text/javascript">

    var currentItem;
    $(document).ready(function() {


        $("#conn").change(function() {
            $("#tree1").loadUrl("/AuthMain/GetDbSchema.bee", { connString: $(this).val() },
            function() {
                bee.initUI($("#treediv"));
            });

        });


        $("#databaseType").change(function() {
        bee.PostData("/AuthMain/GetSqlCode.bee", { connString: $("#conn").val(), dbObject: currentItem, dbType: $(this).val() }, function(msg) {

                document.getElementById('ctlFlash_sql').setText(msg);
            });

        });



        // initialize with parameters
        var flashvars = {
            // indicate the parser,asp / aspx / php / jsp / java / csharp / cpp / javascript / sql / xml / css / html.
            parser: "javascript",

            // set the editor to read-only mode
            readOnly: false,

            // the editor detects client installed fonts and use preferred fonts if installed.
            // NOTE: the vertical bar charactor is required at the begin and end of the list
            preferredFonts: "|Consolas|Courier New|Courier|Arial|Tahoma|",

            // font size
            fontSize: 12,

            // indicate the callback function so that we can load the content into editor once it is initialized.
            onload: "onEditorLoaded"
        };

        // flash player parameters, you can find more information at: http://code.google.com/p/swfobject/wiki/documentation
        var params = { menu: "false", /* wmode : "transparent", */allowscriptaccess: "always" };

        // define the id of the flash control, we need the id in javascript interaction 
        var attributes = { id: "ctlFlash", name: "ctlFlash" };

        // embed the flash with size, more information can be found at: http://code.google.com/p/swfobject/wiki/documentation
        swfobject.embedSWF("/js/CodeHighlightEditor.swf?_=" + (new Date()).getTime(), "flash-loader", "100%", "400", "10.0.0", null, flashvars, params, attributes);

        flashvars.parser = "sql";
        attributes.id = "ctlFlash_sql";
        attributes.name = "ctlFlash_sql";
        swfobject.embedSWF("/js/CodeHighlightEditor.swf?_=" + (new Date()).getTime(), "sql-loader", "100%", "400", "10.0.0", null, flashvars, params, attributes);
    });

    function GetCode(item) {
        currentItem = item;
        $("#divFileBody").loadUrl("/AuthMain/GetCode.bee", { connString: $("#conn").val(), dbObject: item },
        function() {
            var value = $("#divFileBody [name=code]").text();

            document.getElementById('ctlFlash').setText(value);
            document.getElementById('ctlFlash_sql').setText("");
        });
    }
</script>

